﻿using System;
using System.Collections.Generic;
using System.Reflection;
using Autodesk.Revit.DB;

namespace StairsModuleAndEdit.StairsModel.AddSigns
{
	internal static class Utility
	{
		public static string GetAppRootPath()
		{
            return @"C:\Hongye\HYArch2018";
			string text = Assembly.GetExecutingAssembly().Location;
			int length = text.LastIndexOf("\\");
			text = text.Substring(0, length);
			length = text.LastIndexOf("\\");
			return text.Substring(0, length);
		}

		internal static double MMToFeet(double input, bool ifIsMMToFeet = true)
		{
			if (ifIsMMToFeet)
			{
				return input / 304.8;
			}
			return input * 304.8;
		}

		internal static Line GetZAix(XYZ input, bool ifZPluse = true)
		{
			XYZ xyz;
			if (ifZPluse)
			{
				xyz = new XYZ(input.X, input.Y, input.Z + 1.0);
			}
			else
			{
				xyz = new XYZ(input.X, input.Y, input.Z - 1.0);
			}
			return Line.CreateBound(input, xyz);
		}

		internal static XYZ GetMidPoint(XYZ pointOne, XYZ pointTwo)
		{
			return pointOne.Add(pointTwo).Divide(2.0);
		}

		internal static XYZ GetRealPointForLinkFile(RevitLinkInstance inputLinkInstance, ElementId inputELementId)
		{
			Transform transform = inputLinkInstance.GetTransform();
			Document linkDocument = inputLinkInstance.GetLinkDocument();
			Element element = linkDocument.GetElement(inputELementId);
			XYZ point = (element.Location as LocationPoint).Point;
			return Utility.TransformPoint(point, transform);
		}

		internal static XYZ TransformPoint(XYZ point, Transform transform)
		{
			double x = point.X;
			double y = point.Y;
			double z = point.Z;
			XYZ xyz = transform.get_Basis(0);
			XYZ xyz2 = transform.get_Basis(1);
			XYZ xyz3 = transform.get_Basis(2);
			XYZ origin = transform.Origin;
			double num = x * xyz.X + y * xyz2.X + z * xyz3.X + origin.X;
			double num2 = x * xyz.Y + y * xyz2.Y + z * xyz3.Y + origin.Y;
			double num3 = x * xyz.Z + y * xyz2.Z + z * xyz3.Z + origin.Z;
			return new XYZ(num, num2, num3);
		}

		internal static double GetAXYRotateFromTransform(Transform input, out int zuse)
		{
			double result = input.BasisX.Normalize().AngleTo(XYZ.BasisX.Normalize());
			if (input.BasisX.Normalize().Y > XYZ.BasisX.Normalize().Y)
			{
				zuse = 1;
			}
			else
			{
				zuse = -1;
			}
			return result;
		}

		internal static bool IfRefenceHasAdded(ref List<int> lstLinkInstanceid, ref List<int> lstInstanceId, Reference inputRefer)
		{
			int num = Math.Min(lstInstanceId.Count, lstLinkInstanceid.Count);
			for (int i = 0; i < num; i++)
			{
				if (lstLinkInstanceid[i] == inputRefer.ElementId.IntegerValue && lstInstanceId[i] == inputRefer.LinkedElementId.IntegerValue)
				{
					return true;
				}
			}
			lstLinkInstanceid.Add(inputRefer.ElementId.IntegerValue);
			lstInstanceId.Add(inputRefer.LinkedElementId.IntegerValue);
			return false;
		}
	}
}
